from scipy.io import arff
import scipy.io as scio
import pandas as pd
import numpy as np

from CHARACTER import Indicator


class Datasets():
    def __init__(self):
        self.attr=None
    
    def get_data(self,dataset_name):
        if dataset_name=='image':
            self.attr=self.image_data()['attr']
            df=self.image_data()['df']
            data=np.array(df['feature'].tolist())
            target=np.array(df['target'].tolist())
            return [data,target]
        elif dataset_name=='yeast':
             self.attr=self.image_data()['attr']
             df=self.yeast_data()['df']
             data=np.array(df['feature'].tolist())
             target=np.array(df['target'].tolist())
             return [data,target]
        elif dataset_name=='CAL500':
            self.attr=self.CAL500_data()['attr']
            df=self.CAL500_data()['df']
            data=np.array(df['feature'].tolist())
            target=np.array(df['target'].tolist())
            return [data,target]
    
    def image_data(self):

        data_path='Datasets\Image.mat'
        data=scio.loadmat(data_path)
        
        feature=data['data'].tolist()
        target=data['target']
        target=np.transpose(target).tolist()
        
        Image={}
        Image['df']=pd.DataFrame({'feature':feature,'target':target})
        Image['attr']=Indicator(np.array(feature),np.array(target))
        return Image

    def yeast_data(self):
        data_path='Datasets\Yeast.mat'
        data=scio.loadmat(data_path)
    
        feature=data['Xapp'].tolist()+data['Xgen'].tolist()
        target=data['Yapp'].tolist()+data['Ygen'].tolist()

        Yeast={}
        Yeast['df']=pd.DataFrame({'feature':feature,'target':target})
        Yeast['attr']=Indicator(np.array(feature),np.array(target))
        return Yeast
    
    def CAL500_data(self):
        data_path='Datasets\CAL500.mat'
        data=scio.loadmat(data_path)
        
        feature=data['data'].tolist()
        target=data['target']
        target=np.transpose(target).tolist()
        
        CAL500={}
        CAL500['df']=pd.DataFrame({'feature':feature,'target':target})
        CAL500['attr']=Indicator(np.array(feature),np.array(target))
        return CAL500
        
        
        
    
    def birds_data(self):
        pass
    
    def corel5k_data(self):
        pass
    
    def enron_data(self):
        pass
    
    def genbase_data(self):
        pass
    
    def languagelog_data(self):
        pass
    
    def recreation_data(self):
        pass
    
    def scene_data(self):
        pass
    
    def slashdot_data(self):
        pass
    